package com.estar.app.business.mobileLogin.utils;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.log4j.Logger;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.service.CommonService;
import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.core.util.DateUtils;
import org.jeecgframework.core.util.HttpUtil;
import org.jeecgframework.core.util.PasswordUtil;
import org.jeecgframework.core.util.ResourceUtil;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.core.util.YouBianCodeUtil;
import org.jeecgframework.tag.vo.datatable.SortDirection;
import org.jeecgframework.web.system.pojo.base.TSDepart;
import org.jeecgframework.web.system.pojo.base.TSSystemEntity;
import org.jeecgframework.web.system.pojo.base.TSType;
import org.jeecgframework.web.system.pojo.base.TSTypegroup;
import org.jeecgframework.web.system.pojo.base.TSUser;
import org.jeecgframework.web.system.pojo.base.TSUserOrg;
import org.jeecgframework.web.system.pojo.base.TSVersion;
import org.jeecgframework.web.system.service.SystemService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.estar.app.appsrvyyabx.mobile.domain.DataVO;
import com.estar.app.appsrvyyabx.mobile.domain.SubmitImageDetailInfoVO;
import com.estar.app.appsrvyyabx.mobile.domain.VOBase;
import com.estar.app.appsrvyyabx.mobile.domain.VersionVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.CarVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.CaseListVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.CaseUpdateVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.CaseVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.LoginVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.RemarkVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.ReturnUserVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.SmsVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.SurveyExamineVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.SurveyVO;
import com.estar.app.appsrvyyabx.mobile.domain.vo.UserPasswordVO;
import com.estar.app.business.common.service.AppService;
import com.estar.app.business.mobileLogin.controller.DepartCode;
import com.estar.app.business.mobileLogin.controller.TaskReportNoTimer;
import com.estar.app.business.mobileLogin.entity.AppUserEntity;
import com.estar.app.business.mobileLogin.entity.SendSMSEntity;
import com.estar.appuser.util.Des3;
import com.estar.platform.caseInfo.entity.TmblCarInfoEntity;
import com.estar.platform.caseInfo.entity.TmblCaseUpdateInfoEntity;
import com.estar.platform.caseInfo.entity.TmblPicInfoEntity;
import com.estar.platform.caseInfo.entity.TmblPicStateRemarkEntity;
import com.estar.platform.caseInfo.entity.TmblSendSMS;
import com.estar.platform.caseInfo.entity.TmblSurveyInfoEntity;
import com.estar.trafficpolice.entity.TmblTrafficpoliceEntity;

@Component("respCheckUtil")
@Scope("prototype")
public class RespCheckUtil {
	
	@Autowired
	AppService appService;
	
	@Autowired
	private SystemService systemService;
	
	private static final Logger logger = Logger.getLogger(RespCheckUtil.class);
	public final static String C_VERSION_KIND_ANDROID = "ANDROID";
	public final static String C_VERSION_KIND_IOS = "IOS";
	private static SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
	/*旧的短信模板*/
	/*public final static String apikey = "8690df1462adb617607a0d372489689f"; //发送短信apikey
	public final static String smsUrl= "http://sms.yunpian.com/v2/sms/single_send.json"; //发送短信地址
	public final static String getsmsUrl= "http://sms.yunpian.com/v1/sms/get_reply.json"; //获取短信回复地址
	*/
	 //联通的短信模板
	public final static String smsUrl="https://smsapi.ums86.com:9600/sms/Api/Send.do";
	public final static String getsmsUrl = "https://smsapi.ums86.com:9600/sms/Api/reply.do";
	public final static String SpCode="242692";//企业编号
	public final static String LoginName="admin3";//	用户名称
	public final static String Password="gaii38788102"	;//用户密码
	public final static String f="1";	//提交时检测方式
	
	//APP用户登录
	public DataVO login(DataVO dataVO) throws Exception{
		LoginVO loginVO = (LoginVO) dataVO.getList().get(0);
		String empCde = loginVO.getEmpCde();	
		String password = loginVO.getPassWd();
		String sysMrk = loginVO.getSysMrk();
		String version = loginVO.getVersion();
		
		if (empCde==null||"".equals(empCde)) {
			dataVO.setResultCde("0");
			dataVO.setMessage("工号不能为空");
		}
		if (password==null||"".equals(password)) {
			dataVO.setResultCde("0");
			dataVO.setMessage("密码不能为空");
		}
		if (sysMrk==null||"".equals(sysMrk)) {
			dataVO.setResultCde("0");
			dataVO.setMessage("系统类型不能为空");
		}
		if (version==null||"".equals(version)) {
			dataVO.setResultCde("0");
			dataVO.setMessage("版本信息不能为空");
		}
		
		
		AppUserEntity appUser = (AppUserEntity) appService.findUniqueByProperty(AppUserEntity.class,"empCde",empCde);
		
		String p="a";
		String w="c";
		try {
			 w=Des3.decode(appUser.getEmpPassWord());
			p=Des3.decode(password);
			
		} catch (Exception e) {
		
			e.printStackTrace();
		}
		if(null == appUser){
			dataVO.setResultCde("0");
			dataVO.setMessage("没有用户信息");
		}else if(!p.equals(w)){
			dataVO.setResultCde("0");
			dataVO.setMessage("用户密码错误");
		}else{
			dataVO.setResultCde("1");
			dataVO.setMessage("用户验证成功");
			
			List<VOBase> returnUserList = new ArrayList<VOBase>();
			ReturnUserVO returnUser = new ReturnUserVO();
			returnUser.setEmpCde(appUser.getEmpCde());
			returnUser.setEmpDptCde(appUser.getDptCde());
			returnUser.setEmpDptNme(appUser.getDptName());
			returnUser.setEmpNme(appUser.getEmpName());
			returnUser.setMobile(appUser.getPhoneNo());
			if(appUser.getWorkPlace()!=null){
				returnUser.setWorkPlace(appUser.getWorkPlace().getWorkplace());
				returnUser.setWorkPlaceAddress(appUser.getWorkPlace().getAddress());
				returnUser.setWorkPlacePhone(appUser.getWorkPlace().getTelephone());
			}else{
				returnUser.setWorkPlace("");
				returnUser.setWorkPlaceAddress("");
				returnUser.setWorkPlacePhone("");
			}
			returnUser.setEmail(appUser.getEmail());
			returnUser.setArea(appUser.getArea());
			returnUser.setStatue(appUser.getStatue());
			returnUserList.add(returnUser);
			
			dataVO.setList(returnUserList);
			
			
		}
		return dataVO;
	}
	
	//用户密码修改
	public DataVO changePasswork(DataVO dataVO){
		
		try{
			//拿到登录人的信息
			UserPasswordVO upwVO = (UserPasswordVO) dataVO.getList().get(0);
			String empCde = upwVO.getEmpCde();//获取工号
			//找到需要修改的用户
			AppUserEntity appUser = (AppUserEntity) appService.findUniqueByProperty(AppUserEntity.class,"empCde",empCde);
			//验证旧密码和用户，正确就下一步，不正确就返回主界面
			String oldPassPW=upwVO.getOldPassWd();
			if(appUser!=null && oldPassPW.equals(appUser.getEmpPassWord())){
				
				//String newPassPW=PasswordUtil.encrypt(appUser.getEmpCde(),newPW, PasswordUtil.getStaticSalt());
				appUser.setEmpPassWord(upwVO.getNewPassWd());
				//更新保存
				appService.updateEntitie(appUser);
				dataVO.setResultCde("1");
				dataVO.setMessage("密码修改成功");
				
			}else{
				dataVO.setResultCde("0");
				dataVO.setMessage("输入的旧密码或账号不正确");
			}	
		}catch(Exception e){
			logger.error("系统异常：",e);
			dataVO.setResultCde("0");
			dataVO.setMessage("密码修改失败");
			e.printStackTrace();
		}
		//把返回的xml文件里的list数据清除，不显示
		List<VOBase> returnUserList = new ArrayList<VOBase>();		
		dataVO.setList(returnUserList);
		return dataVO;
	}
	
	//案件创建
	public DataVO taskCreate(DataVO dataVO) {
		DataVO returnVo = new DataVO();
		try{
			
			SurveyVO surveyVO = (SurveyVO) dataVO.getList().get(0);
			
			String hql = "from TmblSurveyInfoEntity where t_report_no=?";
			List<TmblSurveyInfoEntity> surveyInfoList = appService.findHql(hql, surveyVO.getReportNo());
			
			//将已存在的图片类别信息删除
			//deleteAll(surveyVO.getReportNo(),appService);
			
			if(null==surveyInfoList || surveyInfoList.size()<=0){
				TmblSurveyInfoEntity surveyInfo = new TmblSurveyInfoEntity();
				surveyInfo = (TmblSurveyInfoEntity) ObjCopyUtils.beansCopy(surveyVO, surveyInfo);
				
				surveyInfo.setCaseStatus("T");
				AppUserEntity user = (AppUserEntity) appService.findUniqueByProperty(AppUserEntity.class,"empCde",surveyVO.getEmpCde());	//查询数据库
				//AppUserEntity user = appService.getEntity(AppUserEntity.class, surveyVO.getEmpCde());
				surveyInfo.setAppUser(user);
				surveyInfo.setCreateTm(new Date());
				surveyInfo.setCheckFlag("0");
				
				
				//创建案件号,并返回给手机端
				String rptNo = TaskReportNoTimer.createRptNo(appService);
				surveyInfo.setReportNo(rptNo);
				surveyVO.setReportNo(rptNo);
				
				for (int i = 0; i < surveyVO.getCarList().size(); i++) {
					CarVO car = surveyVO.getCarList().get(i);
					if("甲方车辆".equals(car.getIndexNme())){
						surveyInfo.setCarsNo(car.getCarNo());
					}
					if("乙方车辆".equals(car.getIndexNme())){
						surveyInfo.setYiCarNo(car.getCarNo());
					}
					//图片类型备注
					List<RemarkVO> remarkList = car.getRemarkList();
					for (int j = 0; j < remarkList.size(); j++) {
						TmblPicStateRemarkEntity picStateEntity = new TmblPicStateRemarkEntity();
						picStateEntity = (TmblPicStateRemarkEntity) ObjCopyUtils.beansCopy(remarkList.get(j), picStateEntity);
						picStateEntity.setCarNo(car.getCarNo());
						picStateEntity.setReportNo(surveyVO.getReportNo());
						appService.save(picStateEntity);
					}
					
					TmblCarInfoEntity carInfo = new TmblCarInfoEntity();
					carInfo = (TmblCarInfoEntity) ObjCopyUtils.beansCopy(car, carInfo);
					carInfo.setReportNo(surveyInfo.getReportNo());
					carInfo.setCreateTm(new Date());
					appService.save(carInfo);
				}
				appService.save(surveyInfo);
			}else{
				TmblSurveyInfoEntity surveyInfo = surveyInfoList.get(0);
				surveyInfo = (TmblSurveyInfoEntity) ObjCopyUtils.beansCopy(surveyVO, surveyInfo);
				surveyInfo.setCaseStatus("T");
				surveyInfo.setUpdateTm(new Date());
				
				String hqlCar = "from TmblCarInfoEntity where t_report_no=?";
				List<TmblCarInfoEntity> carInfoList = appService.findHql(hqlCar,surveyVO.getReportNo());
				
				for (int i = 0; i < carInfoList.size(); i++) {
					CarVO car = surveyVO.getCarList().get(i);
					if("甲方车辆".equals(car.getIndexNme())){
						surveyInfo.setCarsNo(car.getCarNo());
					}
					if("乙方车辆".equals(car.getIndexNme())){
						surveyInfo.setYiCarNo(car.getCarNo());
					}
					TmblCarInfoEntity carInfo = carInfoList.get(i);
					carInfo.setCarNo(car.getCarNo());
					
					appService.saveOrUpdate(carInfo);
					
					//图片类型备注
					/*List<RemarkVO> remarkList = car.getRemarkList();
					for (int j = 0; j < remarkList.size(); j++) {
						TmblPicStateRemarkEntity picStateEntity = new TmblPicStateRemarkEntity();
						picStateEntity = (TmblPicStateRemarkEntity) ObjCopyUtils.beansCopy(remarkList.get(j), picStateEntity);
						picStateEntity.setCarNo(car.getCarNo());
						picStateEntity.setReportNo(surveyVO.getReportNo());
						appService.save(picStateEntity);
					}*/
				}
				appService.saveOrUpdate(surveyInfo);
			}
			
			List<VOBase> baseList = new ArrayList<VOBase>();
			baseList.add(surveyVO);
			returnVo.setList(baseList);
			
			returnVo.setResultCde("1");
			returnVo.setMessage("案件创建成功");
		}catch (Exception e) {
			returnVo.setResultCde("0");
			returnVo.setMessage("案件创建失败");
			logger.error("系统异常：",e);
			e.printStackTrace();
		}
		
		return returnVo;
	}

	
	//案件暂存
	public DataVO taskTemp(DataVO dataVO) {
		DataVO returnVo = new DataVO();
		try{
			
			SurveyVO surveyVO = (SurveyVO) dataVO.getList().get(0);
			String hql = "from TmblSurveyInfoEntity where t_report_no=?";
			List<TmblSurveyInfoEntity> surveyInfoList = appService.findHql(hql, surveyVO.getReportNo());
			
			//将已存在的图片类别信息删除
			deleteAll(surveyVO.getReportNo(),appService);
			
			if(null==surveyInfoList || surveyInfoList.size()<=0){
				returnVo.setResultCde("0");
				returnVo.setMessage("案件不存在");
				return returnVo;
			}else{
				TmblSurveyInfoEntity surveyInfo = surveyInfoList.get(0);
				surveyInfo = (TmblSurveyInfoEntity) ObjCopyUtils.beansCopy(surveyVO, surveyInfo);
				surveyInfo.setCaseStatus("T");
				surveyInfo.setUpdateTm(new Date());
				
				for (int i = 0; i < surveyVO.getCarList().size(); i++) {
					CarVO car = surveyVO.getCarList().get(i);
					if("甲方车辆".equals(car.getIndexNme())){
						if(StringUtil.isNotEmpty(car.getMoblie())){
							surveyInfo.setDriverPhone(car.getMoblie());
						}else{
							surveyInfo.setDriverPhone(car.getPhone());
						}
					}
					if("乙方车辆".equals(car.getIndexNme())){
						if(StringUtil.isNotEmpty(car.getMoblie())){
							surveyInfo.setYiPhone(car.getMoblie());
						}else{
							surveyInfo.setYiPhone(car.getPhone());
						}
						
					}
					String hqlCar = "from TmblCarInfoEntity where t_car_no=? and t_report_no=?";
					List<TmblCarInfoEntity> carInfoList = appService.findHql(hqlCar, car.getCarNo(),surveyVO.getReportNo());
					
					TmblCarInfoEntity carInfo = carInfoList.get(0);
					carInfo = (TmblCarInfoEntity) ObjCopyUtils.beansCopy(car, carInfoList.get(0));
					appService.saveOrUpdate(carInfo);
					
					//图片类型备注
					List<RemarkVO> remarkList = car.getRemarkList();
					for (int j = 0; j < remarkList.size(); j++) {
						TmblPicStateRemarkEntity picStateEntity = new TmblPicStateRemarkEntity();
						picStateEntity = (TmblPicStateRemarkEntity) ObjCopyUtils.beansCopy(remarkList.get(j), picStateEntity);
						picStateEntity.setCarNo(car.getCarNo());
						picStateEntity.setReportNo(surveyVO.getReportNo());
						appService.save(picStateEntity);
					}
				}
				
				appService.saveOrUpdate(surveyInfo);
			}
			
			returnVo.setResultCde("1");
			returnVo.setMessage("案件暂存成功");
		}catch (Exception e) {
			returnVo.setResultCde("0");
			returnVo.setMessage("案件暂存失败");
			logger.error("系统异常：",e);
			e.printStackTrace();
		}
		
		return returnVo;
	}
	
	
	//案件提交
	public DataVO taskSubmit(DataVO dataVO) {
		DataVO returnVo = new DataVO();
		String reportNo = "";
		try{
			SurveyVO surveyVO = (SurveyVO) dataVO.getList().get(0);
			String hql = "from TmblSurveyInfoEntity where t_report_no=?";
			List<TmblSurveyInfoEntity> surveyInfoList = appService.findHql(hql, surveyVO.getReportNo());
			
			//将已存在的图片类别信息删除
			deleteAll(surveyVO.getReportNo(),appService);
			
			if(null==surveyInfoList || surveyInfoList.size()<=0){
				returnVo.setResultCde("0");
				returnVo.setMessage("案件不存在");
				return returnVo;
			}else{
				TmblSurveyInfoEntity surveyInfo = surveyInfoList.get(0);
				surveyInfo = (TmblSurveyInfoEntity) ObjCopyUtils.beansCopy(surveyVO, surveyInfo);
				surveyInfo.setCaseStatus("S");
				surveyInfo.setDangerTime(surveyVO.getDangerTime());
				surveyInfo.setUpdateTm(new Date());
				surveyInfo.setSpotCheck("n");
				//维护交警大队数字字典
				/*TSTypegroup tGroup = appService.findUniqueByProperty(TSTypegroup.class, "typegroupcode", "trafficPo");
				String hql2 = "from TSType where typegroupid=? and typename=?";	
				List<TSType> types=appService.findHql(hql2, tGroup.getId(),surveyInfo.getTrafficPolice());
				if(types.size()==0){
					TSType type=new TSType();
					type.setTypename(surveyInfo.getTrafficPolice());
					type.setTypecode("020");
					type.setTSTypegroup(tGroup);
					appService.save(type);
					
				}*/
				//维护交警大队
				List<TmblTrafficpoliceEntity> police =appService.findByProperty(TmblTrafficpoliceEntity.class, "trafficpolice", surveyInfo.getTrafficPolice());
				if(police==null || police.size()==0){
					TmblTrafficpoliceEntity newPolice=new TmblTrafficpoliceEntity();
					newPolice.setTrafficpolice(surveyInfo.getTrafficPolice());
					newPolice.setTelephon("020");
					newPolice.setCity(surveyInfo.getEmpDptCde());
					newPolice.setArea(surveyInfo.getAppUser().getArea());
					appService.save(newPolice);
				}
				
				
				for (int i = 0; i < surveyVO.getCarList().size(); i++) {
					CarVO car = surveyVO.getCarList().get(i);
					
					if("甲方车辆".equals(car.getIndexNme())){
						
						surveyInfo.setJiaDriName(car.getDriverNme());//甲方车主名称
						
						if(StringUtil.isNotEmpty(car.getMoblie())){
							surveyInfo.setDriverPhone(car.getMoblie());
						}else{
							surveyInfo.setDriverPhone(car.getPhone());
						}
					}
					if("乙方车辆".equals(car.getIndexNme())){
						
						surveyInfo.setYiDriName(car.getDriverNme());//乙方车主名称
						
						if(StringUtil.isNotEmpty(car.getMoblie())){
							surveyInfo.setYiPhone(car.getMoblie());
						}else{
							surveyInfo.setYiPhone(car.getPhone());
						}
						surveyInfo.setYiCarNo(car.getCarNo());
					}
					if(car.getBusinessLogo().equals("N")){
						TSDepart newDep=new TSDepart();
						String company=car.getBusinessCompany();
						String phone=car.getBusinessPhone();
						TSDepart dep=appService.findUniqueByProperty(TSDepart.class, "departname", car.getBusinessCompany());
						if(dep==null){
							TSDepart parentDep=appService.findUniqueByProperty(TSDepart.class, "departname", "省保险");
							String localMaxCode  = DepartCode.getMaxLocalCode(parentDep.getOrgCode(),appService);
							String code=YouBianCodeUtil.getSubYouBianCode(parentDep.getOrgCode(), localMaxCode);
							newDep.setOrgCode(code);
							newDep.setOrgType("2");
							newDep.setTSPDepart(parentDep);
							newDep.setDepartname(company);
							newDep.setDescription(company);
							newDep.setMobile(phone);
							newDep.setAddress("广东");
							appService.save(newDep);
							car.setBusinessCompany(code);
						}else{
							car.setBusinessCompany(dep.getOrgCode());
						}
					}
					if(car.getCompulsoryLogo().equals("N")){
						TSDepart newDep=new TSDepart();
						String company=car.getCompulsoryCompany();
						String phone=car.getCompulsoryPhone();
						TSDepart dep=appService.findUniqueByProperty(TSDepart.class, "departname", car.getCompulsoryCompany());
						if(dep==null ){
							TSDepart parentDep=appService.findUniqueByProperty(TSDepart.class, "departname", "省保险");
							String localMaxCode  = DepartCode.getMaxLocalCode(parentDep.getOrgCode(),appService);
							String code=YouBianCodeUtil.getSubYouBianCode(parentDep.getOrgCode(), localMaxCode);
							newDep.setOrgCode(code);
							newDep.setOrgType("2");
							newDep.setTSPDepart(parentDep);
							newDep.setDepartname(company);
							newDep.setDescription(company);
							newDep.setMobile(phone);
							newDep.setAddress("广东");
							appService.save(newDep);
							car.setCompulsoryCompany(code);
						}else{
							car.setCompulsoryCompany(dep.getOrgCode());
						}
						
					}
					String hqlCar = "from TmblCarInfoEntity where t_car_no=? and t_report_no=?";
					List<TmblCarInfoEntity> carInfoList = appService.findHql(hqlCar, car.getCarNo(),surveyVO.getReportNo());
					
					TmblCarInfoEntity carInfo = carInfoList.get(0);
					
					carInfo = (TmblCarInfoEntity) ObjCopyUtils.beansCopy(car, carInfoList.get(0));
					
					//图片类型备注
					List<RemarkVO> remarkList = car.getRemarkList();
					for (int j = 0; j < remarkList.size(); j++) {
						TmblPicStateRemarkEntity picStateEntity = new TmblPicStateRemarkEntity();
						picStateEntity = (TmblPicStateRemarkEntity) ObjCopyUtils.beansCopy(remarkList.get(j), picStateEntity);
						picStateEntity.setCarNo(car.getCarNo());
						picStateEntity.setReportNo(surveyVO.getReportNo());
						appService.save(picStateEntity);
					}
					
					appService.saveOrUpdate(carInfo);
				}
				
				appService.saveOrUpdate(surveyInfo);
				
				reportNo = surveyInfo.getReportNo();
				//System.out.println(reportNo);
			}
			
			
			returnVo.setResultCde("1");
			returnVo.setMessage("案件提交成功");
			
			
			
		}catch (Exception e) {
			returnVo.setResultCde("0");
			returnVo.setMessage("案件提交失败");
			logger.error("系统异常：",e);
			e.printStackTrace();//lo4j打印
			
		}
		//发送满意度调查短信
		try{
			sendSMSInvestigation(reportNo);
		}catch (Exception e) {
			logger.error("系统异常：",e);
			
		}
		return returnVo;
	}

	
	//案件销毁
	public DataVO taskDestroy(DataVO dataVO) {
		DataVO returnVo = new DataVO();
		try{
			SurveyVO surveyVO = (SurveyVO) dataVO.getList().get(0);
			String hql = "from TmblSurveyInfoEntity where t_report_no=?";
			List<TmblSurveyInfoEntity> surveyInfoList = appService.findHql(hql, surveyVO.getReportNo());
			
			//将已存在的图片类别信息删除
			deleteAll(surveyVO.getReportNo(),appService);
			
			if(null==surveyInfoList || surveyInfoList.size()<=0){
				returnVo.setResultCde("0");
				returnVo.setMessage("案件不存在");
				return returnVo;
			}else{
				TmblSurveyInfoEntity surveyInfo = surveyInfoList.get(0);
				surveyInfo = (TmblSurveyInfoEntity) ObjCopyUtils.beansCopy(surveyVO, surveyInfo);
				surveyInfo.setCaseStatus("C");
				surveyInfo.setUpdateTm(new Date());
				surveyInfo.setCheckFlag("2");
				appService.saveOrUpdate(surveyInfo);
			}
			
			for (int i = 0; i < surveyVO.getCarList().size(); i++) {
				CarVO car = surveyVO.getCarList().get(i);
				String hqlCar = "from TmblCarInfoEntity where t_car_no=? and t_report_no=?";
				List<TmblCarInfoEntity> carInfoList = appService.findHql(hqlCar, car.getCarNo(),surveyVO.getReportNo());
				
				TmblCarInfoEntity carInfo = carInfoList.get(0);
				carInfo = (TmblCarInfoEntity) ObjCopyUtils.beansCopy(carInfo, carInfoList.get(0));
				
				appService.saveOrUpdate(carInfo);
			}
			
			returnVo.setResultCde("1");
			returnVo.setMessage("案件注销成功");
		}catch (Exception e) {
			logger.error("系统异常：",e);
			returnVo.setResultCde("0");
			returnVo.setMessage("案件注销失败");
		}
		
		return returnVo;
	}
	
	
	//图片上传
	public DataVO uploadImg(DataVO dataVO) {
		DataVO returnVo = new DataVO();
		try{
			SubmitImageDetailInfoVO imgVO = (SubmitImageDetailInfoVO) dataVO.getList().get(0);
			
			/*图片存在本地*/
			SimpleDateFormat sdflocal = new SimpleDateFormat("yyyy-MM-dd");
			String classLocalPath = this.getClass().getClassLoader().getResource("").getPath();
			classLocalPath = classLocalPath.replaceAll("%20", " ");
			classLocalPath = classLocalPath.substring(0, classLocalPath.indexOf("WEB-INF"));
			
			String vhlNo = imgVO.getImageVhlNO();		//路径显示处理  公共单证信息
			if(null == imgVO.getImageVhlNO() || "".equals(imgVO.getImageVhlNO())){
				vhlNo = "公共单证";
			}
			
			//加一个日期分类
			Date d=new Date();
			String date=df.format(d);
			
			String fileLocalName="picture/"+date+"/"+imgVO.getImageCaseCode()+"/"+vhlNo+"/"+sdflocal.format(new Date());
			File dir1 = new File(classLocalPath+fileLocalName);
			if(!dir1.exists()){
				dir1.mkdirs(); 
			}
			fileLocalName+="/"+imgVO.getLossItemSerialNo()+"_"+System.currentTimeMillis()+"_"+imgVO.getImgHashCode()+".jpg";
			
			boolean flag = ImgUtils.GenerateImage(imgVO.getImagebyte(),classLocalPath+fileLocalName);
			
			if(flag){
				TmblPicInfoEntity picInfoEntity = new TmblPicInfoEntity();
				picInfoEntity = (TmblPicInfoEntity) ObjCopyUtils.beansCopy(imgVO, picInfoEntity);
				picInfoEntity.setImgPath(fileLocalName);
				picInfoEntity.setImagebyte("");
				appService.save(picInfoEntity);
				
				returnVo.setResultCde("1");
				returnVo.setMessage("案件提交成功");
			}else{
				returnVo.setResultCde("0");
				returnVo.setMessage("图片提交成功");
			}
			
			
			
		}catch (Exception e) {
			logger.error("系统异常：",e);
			returnVo.setResultCde("0");
			returnVo.setMessage("图片提交失败");
		
		}
		
		return returnVo;
	}


	//案件查询
	public DataVO taskSearch(DataVO dataVO) {
		DataVO returnVo = new DataVO();
		try{
			CaseVO caseVO = (CaseVO) dataVO.getList().get(0);	
			String empCde = caseVO.getEmpCde();
			String dptCde = caseVO.getEmpDptCde();
			String rptNoOrCarNo = caseVO.getContent();
			String dangerTmBegin = caseVO.getDangerTmBegin();
			String dangerTmEnd = caseVO.getDangerTmEnd(); 
			
			CriteriaQuery cq = new CriteriaQuery(TmblSurveyInfoEntity.class);
			AppUserEntity appUser = (AppUserEntity) appService.findUniqueByProperty(AppUserEntity.class,"empCde",empCde);
			
			if(StringUtil.isNotEmpty(dataVO.getMessage()) && dataVO.getMessage().equals("examine")){
				cq.createAlias("appUser", "c");
				cq.eq("c.area", "2");
			}else{
				cq.eq("appUser", appUser);
				cq.eq("empDptCde", dptCde);
			}
			
			//车牌-案件号查询
			if(checkCarNo(rptNoOrCarNo)){
				cq.like("carsNo", "%"+rptNoOrCarNo+"%");
			}
			else{
				cq.like("reportNo", "%"+rptNoOrCarNo+"%");
			}
			
			if(null!=dangerTmBegin && !"".equals(dangerTmBegin) && null!=dangerTmEnd && !"".equals(dangerTmEnd)){
				cq.add(Restrictions.sqlRestriction("to_date({alias}.t_danger_time,'yyyy-MM-dd HH24:mi:ss') between to_date('"+dangerTmBegin+"','yyyy-MM-dd HH24:mi:ss') and to_date('"+dangerTmEnd+"','yyyy-MM-dd HH24:mi:ss')"));
			}
			
			cq.addOrder("createTm",SortDirection.desc);
			cq.add();
			List<TmblSurveyInfoEntity> surveyList = appService.getListByCriteriaQuery(cq, false);
			
			//把数据的entity类转换为VO类
			List<VOBase> surveyVOList = new ArrayList<VOBase>();
			List<SurveyVO> surList = new ArrayList<SurveyVO>();
			CaseListVO caseListVO = new CaseListVO();
			for (int i = 0; i < surveyList.size(); i++) {
				SurveyVO surveyVO = new SurveyVO();//数据装换
				ObjCopyUtils.beansCopy(surveyList.get(i), surveyVO);
				
				CriteriaQuery cq1 = new CriteriaQuery(TmblCarInfoEntity.class);
				cq1.eq("reportNo", surveyVO.getReportNo());
				cq1.add();
				List<TmblCarInfoEntity> carInfoList = appService.getListByCriteriaQuery(cq1, false);
				List<CarVO> carList = new ArrayList<CarVO>();
				for (int j = 0; j < carInfoList.size(); j++) {
					CarVO carVO = new CarVO();
					ObjCopyUtils.beansCopy(carInfoList.get(j), carVO);
					//判断保险公司是否新增
					if(carVO.getBusinessLogo().equals("N")){
						TSDepart parentDep=appService.findUniqueByProperty(TSDepart.class, "orgCode", carVO.getBusinessCompany());
						if(parentDep!=null){
						
							carVO.setBusinessCompany(parentDep.getDepartname());
							carVO.setBusinessPhone(parentDep.getMobile());
						}
						
					}
					if(carVO.getCompulsoryLogo().equals("N")){
						TSDepart parentDep=appService.findUniqueByProperty(TSDepart.class, "orgCode", carVO.getCompulsoryCompany());
						if(parentDep!=null){
							carVO.setCompulsoryCompany(parentDep.getDepartname());
							carVO.setCompulsoryPhone(parentDep.getMobile());
						}
					}
					carList.add(carVO);
				}
				surveyVO.setCarList(carList);
				surList.add(surveyVO);
				
				//caseListVO.setSurList(surList)
				//surveyVOList.add(surveyVO);
			}
			caseListVO.setSurList(surList);
			surveyVOList.add(caseListVO);
			returnVo.setResultCde("1");
			returnVo.setMessage("案件查询成功");
			returnVo.setAction("task");
			returnVo.setMethod("caseSearch");
			returnVo.setList(surveyVOList);
			
		}catch (Exception e) {
			logger.error("系统异常：",e);
			returnVo.setResultCde("0");
			returnVo.setMessage("案件查询失败");
		
		}
		
		return returnVo;
	}
	
	//发送验证码
	public DataVO sendIdentifyingCode(DataVO dataVO) {
		DataVO returnVo = new DataVO();
		try{
			SmsVO smsVO = (SmsVO) dataVO.getList().get(0);

			//System.out.println("=======controlle保存库入口=================");	
			String phone = smsVO.getPhone();// 手机号
			String msgType = smsVO.getMsgType(); //短信类型（1手机号验证）
			if (null == msgType || "".equals(msgType)){
				msgType = "1";
			}
			// 产生短信验证码
			String smsCode = "";
			for (int i = 0; i < 6; i++) {
				Random rd = new Random();
				smsCode += rd.nextInt(9);
			}
			
			//System.out.println("======验证码生成=====" + smsCode);
			    
		    String smsContent = smsVO.getContent();
		    
		    String sMessageInfo = "";
		    String message = "";
		    String smsId="";
		   
		    if(null == smsContent || "".equals(smsContent)){
		    	//旧模板
		    	//sMessageInfo = "【广州市快撤理赔】您的验证码是" + smsCode + "。如非本人操作，请忽略本短信。" ;
		    	//联通模板
		    	sMessageInfo = "您的验证码是" + smsCode + "。如非本人操作，请忽略本短信。" ;
		    }
		    
		    smsId="code"+smsVO.getReportNo();
		    returnVo.setResultCde("0");
			returnVo.setMessage("短信发送失败，请重试");
		    
		    String result = "";
			//调用短信平台接口发送短信
		    
		  //联通模板
		    result = sendSms(sMessageInfo,phone,smsId);//联通
		    Map record = ParseReplayUtil.parse(result);
		    String replay=(String) record.get("RESULT");
		  //联通
			   if(replay.equals("0")){
			    	returnVo.setResultCde("1");
					returnVo.setMessage("验证码发送成功");
			    }else{
			    	System.out.println("验证码回复："+replay);
			    }
			   
		    
		  //旧的模板	
		   /* result = sendSms(sMessageInfo, phone);    
		    //旧模板
		    if(null != result && !"".equals(result)){
		    	Map<String, Object> map = (Map<String, Object>)JSONObject.parse(result);
		    	
		    	if(null != map.get("code") && "0".equals(map.get("code").toString())){
		    		returnVo.setResultCde("1");
					returnVo.setMessage("验证码发送成功");
		    	}
		    }*/
		    
		    
			//System.out.println("===短信发送成功===");

			//System.out.println("===记录短信发送数据记录，以便核对===");
			SendSMSEntity sms = new SendSMSEntity(phone, smsVO.getReportNo(), smsCode, sMessageInfo, "system", new Date(), msgType);
			
			message = "短信信息添加成功";
			appService.save(sms);
			appService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
			
			returnVo.setAction("task");
			returnVo.setMethod("sendIdentifyingCode");
		}catch (Exception e) {
			logger.error("系统异常：",e);
			returnVo.setResultCde("0");
			returnVo.setMessage("验证码发送失败");
		
		}finally{
			return returnVo;
		}
		
	}
	
	//验证验证码
	public DataVO checkIdentifyingCode(DataVO dataVO) {
		DataVO returnVo = new DataVO();
		String message = "";
		
		try{
			SmsVO smsVO = (SmsVO) dataVO.getList().get(0);

			System.out.println("=======controlle保存库入口=================");	
			String phone = smsVO.getPhone();// 手机号
			String msgType = smsVO.getMsgType(); //短信类型（1手机号验证）
			if (null == msgType || "".equals(msgType)){
				msgType = "1";
			}
			
			CriteriaQuery cq = new CriteriaQuery(SendSMSEntity.class);
			cq.isNull("customResponse");//验证时间为空
			cq.eq("phone", phone);//手机号
			cq.eq("smsCode", smsVO.getIdentifyingCode());//验证码
			//当前时间3分钟内有效
			cq.between("sendSmsDate", DateUtils.parseDate(DateUtils.getDateBeforeMin(DateUtils.getSysDate(), 3), "yyyy-MM-dd HH:mm:ss"), new Date());
			cq.addOrder("sendSmsDate", SortDirection.desc); //按发送时间，降序排列
			cq.add();
			
			List<SendSMSEntity>  sendSmsList = appService.getListByCriteriaQuery(cq, false);
			SendSMSEntity sms = new SendSMSEntity();
			if(null != sendSmsList && sendSmsList.size() > 0){
				sms = sendSmsList.get(0);
				sms.setCustomResponse(new Date());
				appService.saveOrUpdate(sms);
				returnVo.setResultCde("1");
				returnVo.setMessage("验证成功");
			}else{
				returnVo.setResultCde("0");
				returnVo.setMessage("验证码无效，请重试");
			}
			
			message = "手机号验证成功";
			
			appService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
			
			returnVo.setAction("task");
			returnVo.setMethod("checkIdentifyingCode");
		}catch (Exception e) {
			logger.error("系统异常：",e);
			returnVo.setResultCde("0");
			returnVo.setMessage("短信验证失败");
			
		}finally{
			return returnVo;
		}
	}
	
	//发送满意度调查短信
	public String sendSMSInvestigation(String reportNo)throws Exception {
		
		CriteriaQuery cq = new CriteriaQuery(TmblSurveyInfoEntity.class);
		cq.eq("reportNo", reportNo);
		cq.add();
		TmblSurveyInfoEntity surveyInfo = (TmblSurveyInfoEntity)appService.getListByCriteriaQuery(cq, false).get(0);
		
		CriteriaQuery cq1 = new CriteriaQuery(TmblCarInfoEntity.class);
		cq1.eq("reportNo", reportNo);
		cq1.add();
		List<TmblCarInfoEntity> carInfoList = appService.getListByCriteriaQuery(cq1, false);
				
		String visitPhone = ""; // 接收人手机号
		String sMessageInfo = ""; // 短信内容

		// 获取当前时间
		Date sendTime = new Date();
		// 短信输出时间转换
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

		String sendPerson = surveyInfo.getAppUser().getEmpCde(); 		//发送人（查勘员编号）
		try {
			for (TmblCarInfoEntity carInfo : carInfoList) {
				String time =sdf.format(carInfo.getCreateTm());
				String address = surveyInfo.getWorkSpace();
				//旧模板
			/*	sMessageInfo = "【广州市快撤理赔】尊敬的车主：您好，您于" + time + "时间在"
						+ address + "成功办理了一宗轻微交通事故快撤理赔案件，请您对我们快撤理赔点的"
						+ "服务进行评价，直接回复对应数字（1 代表非常满意；2 代表满意；0 代表不满意 ），感谢您的配合！";
				*/
				//联通模板
				sMessageInfo = "尊敬的车主：您好，您于" + time + "时间在"
						+ address + "成功办理了一宗轻微交通事故快撤理赔案件，请您对我们快撤理赔点的"
						+ "服务进行评价，直接回复对应数字（1 代表非常满意；2 代表满意；0 代表不满意 ），感谢您的配合！";

				String result = ""; // 返回结果

				// 事故方手机号码
				if ("是".equals(carInfo.getIfExce())) {
					visitPhone = carInfo.getMoblie();
				} else {
					visitPhone = carInfo.getPhone();
				}
				
				
				// 调用短信平台接口发送短信
				Date d=new Date();
				SimpleDateFormat sdf1=new SimpleDateFormat("yyyyMMddHHmmssSS");
				String smsId=sdf1.format(d);
				//联通的模板
				result = sendSms(sMessageInfo, visitPhone,smsId);
				
				//原来的模板
				//result = sendSms(sMessageInfo, visitPhone);
				
				//记录短信发送数据记录，以便核对
				TmblSendSMS sms = new TmblSendSMS(visitPhone, reportNo, sendTime, "", sendPerson);
				appService.save(sms);
			}

		} catch (Exception e) {
			logger.error("系统异常：",e);
			throw e;
		}
		return null;
	}
		
	//接收回复短信并解析成对象序列,旧模板
	/*public static List<ReturnSMSReplyEntity> returnSMS(String startTime, String endTime, Integer pageNum) throws Exception {
		String result = "";
		try {
			result = getSms(startTime, endTime, pageNum);
			if(null != result && !"".equals(result)){
		
				//将字符串解析成ReturnSMSEntity对象
				ReturnSMSEntity returnSMSEntity = JSONObject.parseObject(result, ReturnSMSEntity.class);
				//返回List并交由定时器管理
				if(null != returnSMSEntity && !"".equals(returnSMSEntity)){
					List<ReturnSMSReplyEntity> returnSMSList = returnSMSEntity.getSms_reply();
					if(null != returnSMSList && !"".equals(returnSMSList)){
						return returnSMSList;
					}
				}
			}
		} catch (Exception e) {
		logger.error(e);
			throw e;
		}
		return null;
	}*/
	
	//联通
	public static JSONArray returnSMS() throws Exception {
		String result = "";
		try {
			result = getSms();
			//System.out.println("回访满意度结果："+result);
			JSONArray array = new JSONArray();
			Map record = ParseReplayUtil.parse(result);
			if(record.containsKey("REPLYS")){
				String replys = (String)record.get("REPLYS");
				array = JSON.parseArray(replys);
			}
			return array;
		} catch (Exception e) {
			logger.error("系统异常：",e);
			throw e;
		}
	}
	
	/**
	 * 智能匹配模板接口发短信
	 *
	 * @param apikey apikey
	 * @param text   　短信内容
	 * @param mobile 　接受的手机号
	 * @param spcode 
	 * @return json格式字符串
	 * @throws Exception 
	 * String smsId 是联通模板需要的
	 */
	
	 /*public static String sendSms(String text, String mobile) throws Exception {
	     //原来的短信发送模板
	     Map<String, String> params = new HashMap<String, String>();
	     params.put("apikey", apikey);
	     params.put("text", text);
	     params.put("mobile", mobile);
	     return HttpUtil.sendPostRequestSetTime(smsUrl, params);
	 }*/
	 public static String sendSms(String text, String mobile, String smsId) throws Exception {
		 //联通模板
		 	HttpClient httpclient = new HttpClient();
			PostMethod post = new PostMethod(smsUrl);
			post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"gbk");
			post.addParameter("SpCode", SpCode);
			post.addParameter("LoginName", LoginName);
			post.addParameter("Password", Password);
			post.addParameter("MessageContent", text);
			post.addParameter("UserNumber", mobile);
			post.addParameter("SerialNumber", smsId);
			post.addParameter("ScheduleTime", "");
			post.addParameter("ExtendAccessNum", "");
			post.addParameter("f", f);
			httpclient.executeMethod(post);
			String info = new String(post.getResponseBody(),"gbk");
			httpclient.getHttpConnectionManager().closeIdleConnections(0);
			return info;
	    
	 }
	 //接收回复短信字符串，旧模板
	/* public static String getSms(String startTime,  String endTime, Integer pageNum) throws Exception{
		 Map<String, String> params = new HashMap<String, String>();
		 	params.put("apikey", apikey);
			params.put("start_time", startTime);
			params.put("end_time", endTime);
			params.put("page_num", pageNum.toString());
			params.put("page_size", "100");
			return HttpUtil.sendPostRequestSetTime(getsmsUrl, params);
	 }*/
	 
	 //联通模板
	 public static String getSms() throws Exception{
	     	HttpClient httpclient = new HttpClient();
			PostMethod post = new PostMethod(getsmsUrl);
			post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"gbk");
			post.addParameter("SpCode", SpCode);
			post.addParameter("LoginName", LoginName);
			post.addParameter("Password", Password);
			httpclient.executeMethod(post);
			String info = new String(post.getResponseBody(),"gbk");
			httpclient.getHttpConnectionManager().closeIdleConnections(0);
			return info;
	     
	 }
	 
	 
	 /**
	 * 通过模板发送短信(不推荐)
	 *
	 * @param apikey    apikey
	 * @param tpl_id    　模板id
	 * @param tpl_value 　模板变量值
	 * @param mobile    　接受的手机号
	 * @return json格式字符串
	 * @throws IOException
	 */
	 /*public static String tplSendSms(String apikey, long tpl_id, String tpl_value, String mobile) throws Exception {
	     Map<String, String> params = new HashMap<String, String>();
	     params.put("apikey", apikey);
	     params.put("tpl_id", String.valueOf(tpl_id));
	     params.put("tpl_value", tpl_value);
	     params.put("mobile", mobile);
	     return HttpUtil.sendPostRequestSetTime("https://sms.yunpian.com/v2/sms/tpl_single_send.json", params);
	 }*/
	 
	 
	
	/**
	 * 正则表达式判断车牌号是否合格
	 * @param carNos
	 * @return
	 */
	protected boolean checkCarNo(String carNos) {
		// String vehicleNoStyle = "^[\u4e00-\u9fa5]{1}[A-Z0-9]{6}$";
		String re1 = "(^[\u4e00-\u9fa5]{1}|^WJ)(.{5,11}$)";
		String re2 = "(^WJ([A-Z0-9\u4E00-\u9FA5])+([A-Z0-9\u4E00-\u9FA5]$))|(^.([A-Z0-9\u4E00-\u9FA5])+([A-Z0-9\u4E00-\u9FA5]$))";

		Pattern pattern1 = Pattern.compile(re1);
		Matcher matcher1 = pattern1.matcher(carNos);

		Pattern pattern2 = Pattern.compile(re2);
		Matcher matcher2 = pattern2.matcher(carNos);
		if (!matcher1.matches() || !matcher2.matches()) 
			return false;
		
		return true;
	}
	
	 /* @Test
	  public void test() throws Exception{
		Map<String, String> params = new HashMap<String, String>();
		HttpClient httpclient = new HttpClient();
		PostMethod post = new PostMethod(smsUrl);
		post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"gbk");
		post.addParameter("SpCode", SpCode);
		post.addParameter("LoginName", LoginName);
		post.addParameter("Password", Password);
		String sMessageInfo = "您的验证码是1111。如非本人操作，请忽略本短信。";
		post.addParameter("MessageContent", sMessageInfo);
		post.addParameter("UserNumber", "13250313216");
		post.addParameter("SerialNumber", "1");
		post.addParameter("ScheduleTime", "");
		post.addParameter("ExtendAccessNum", "");
		post.addParameter("f", f);
		httpclient.executeMethod(post);
		String info = new String(post.getResponseBody(),"gbk");
		
	 }*/
	/*public static void main(String[] args) throws Exception {
		Map<String, String> params = new HashMap<String, String>();
	     
		 params.put("SpCode", SpCode);
	     params.put("LoginName", LoginName);
	     params.put("Password", Password);
	     params.put("MessageContent", "您的验证码是1111。如非本人操作，请忽略本短信。");
	     params.put("UserNumber", "13250313216");
	     params.put("SerialNumber", "1111");
	     params.put("f", f);
	     System.out.println("1111");
	     System.out.println(HttpUtil.sendPostRequestSetTime(smsUrl, params));
	}	*/
	/**
	 * 删除全部
	 */
	public void deleteAll(String reportNo,CommonService commonService){
		/*CriteriaQuery cq = new CriteriaQuery(TmblPicStateRemarkEntity.class);
		cq.eq("reportNo", reportNo);
		cq.add();
		List<TmblPicStateRemarkEntity> picStateList = commonService.getListByCriteriaQuery(cq,false);*/
		
		String hql = "from TmblPicStateRemarkEntity where T_REPORT_NO=?";
		List<TmblPicStateRemarkEntity> picStateList = appService.findHql(hql, reportNo);
		if (picStateList!=null && picStateList.size()>0) {
			for(TmblPicStateRemarkEntity p:picStateList){
				
					systemService.delete(p);
				
			}
		}
		//commonService.deleteAllEntitie(picStateList);
		//commonService.delete(entity);
	}
	
	//案件修改
	public DataVO taskUpdate(DataVO dataVO) {
		DataVO returnVo = new DataVO();
		try{
			CaseUpdateVO caseUpdateVO = (CaseUpdateVO) dataVO.getList().get(0);
			String reportNo = caseUpdateVO.getReportNo();
			
			//查询更改案件
			CriteriaQuery cq = new CriteriaQuery(TmblSurveyInfoEntity.class);
			cq.eq("reportNo", reportNo);
			cq.add();
			List<TmblSurveyInfoEntity> surveyList = appService.getListByCriteriaQuery(cq, false);
			
			//修改案件状态
			if(null!=surveyList && surveyList.size()>0){
				TmblSurveyInfoEntity surInfo = surveyList.get(0);
	 			surInfo.setIfModify(caseUpdateVO.getIfModify());
	 			surInfo.setUpdateRemark(caseUpdateVO.getUpdateRemark());
	 			appService.saveOrUpdate(surInfo);
	 			
	 			TmblCaseUpdateInfoEntity caseUpdateInfo = new TmblCaseUpdateInfoEntity();
	 			caseUpdateInfo.setSubmitTime(new Date());
	 			caseUpdateInfo.setSubmitCode(caseUpdateVO.getEmpCde());
	 			caseUpdateInfo.setUpdateReportNo(reportNo);
	 			caseUpdateInfo.setExpand(caseUpdateVO.getUpdateRemark());
	 			appService.save(caseUpdateInfo);
	 			
	 			returnVo.setResultCde("1");
				returnVo.setMessage("案件修改申请提交成功");
				returnVo.setAction("task");
				returnVo.setMethod("taskUpdate");
			}else{
				returnVo.setResultCde("0");
				returnVo.setMessage("案件号不存在");
				returnVo.setAction("task");
				returnVo.setMethod("taskUpdate");
			}
			
 			
		}catch (Exception e) {
			logger.error("系统异常：",e);
			returnVo.setResultCde("0");
			returnVo.setMessage("案件修改申请提交失败");
		
		}
		
		return returnVo;
	}
	
	/*案件审核*/
	public DataVO surveyExamine(DataVO dataVO){
		DataVO returnVo = new DataVO();
		SurveyExamineVO seVo=(SurveyExamineVO) dataVO.getList().get(0);
		TmblSurveyInfoEntity survey=appService.findUniqueByProperty(TmblSurveyInfoEntity.class, "reportNo",seVo.getReportNo());
		if(seVo.getSurveyExamine().equals("p")){
			survey.setSurveyExamine("p");
			returnVo.setMessage("审核通过");
			returnVo.setResultCde("1");
		}else if(seVo.getSurveyExamine().equals("f")){
			survey.setSurveyExamine("f");
			survey.setSurveyExamineInfo(seVo.getSurveyExamineInfo());
			returnVo.setMessage("审核不通过");
			returnVo.setResultCde("0");
		}
		AppUserEntity appUser =appService.findUniqueByProperty(AppUserEntity.class, "empCde",seVo.getSurveyExamineUser());
		survey.setSurveyExamineUser(appUser.getEmpName());
		appService.updateEntitie(survey);
		returnVo.setMethod("surveyExamine");
		return returnVo;
		
	}
	//获取审核案件的图片
	public DataVO getPic(DataVO dataVO,HttpServletRequest request){
		DataVO returnVo = new DataVO();
		SubmitImageDetailInfoVO picVo=(SubmitImageDetailInfoVO) dataVO.getList().get(0);
		List<VOBase> picVoList=new ArrayList<VOBase>();
		List<TmblPicInfoEntity> picList = new ArrayList<TmblPicInfoEntity>();
		CriteriaQuery cq = new CriteriaQuery(TmblPicInfoEntity.class);
		cq.eq("imageCaseCode", picVo.getImageCaseCode());
		cq.add();
		picList = appService.getListByCriteriaQuery(cq, false);
		if(picList.size()>0){
			String strBackUrl = "http://" + request.getServerName() //服务器地址  
			+ ":"   
			+ request.getServerPort()//端口号  
			+ request.getContextPath() +"/" ;    //项目名称  
			for(TmblPicInfoEntity p:picList){
				p.setImgPath(strBackUrl+p.getImgPath());
				SubmitImageDetailInfoVO s=new SubmitImageDetailInfoVO();
				ObjCopyUtils.beansCopy(p, s);
				picVoList.add(s);
			}
			returnVo.setList(picVoList);
			returnVo.setMessage("获取图片成功");
			returnVo.setResultCde("1");
		}else{
			returnVo.setMessage("获取图片失败");
			returnVo.setResultCde("0");
		}
		returnVo.setMethod("getPic");
		
		return returnVo;
	}
	/**
	 * 获取最新版本信息
	 */
	public DataVO getVersion(DataVO dataVO) throws Exception {

		DataVO returnVo = new DataVO();
		; // 封装返回的错误代码及错误信息的VO
		try {
			/***************
			 * IOS上线增加版本更新功能 begin qinfx 20150527
			 **********************/
			VersionVO version = (VersionVO) dataVO.getList().get(0);
			String sysMrk = "";
			String urlStr = "";// 版本下载地址
			String verDownloadUrl = ""; // 更新包下载地址
			String clientSystemInfo = "ANDROID"; // 区分手机请求版本
													// 是 ANDROID
													// IOS
			if (clientSystemInfo != null && clientSystemInfo.toUpperCase().indexOf(C_VERSION_KIND_ANDROID) >= 0) {// andorid版本较验
				sysMrk = C_VERSION_KIND_ANDROID;
			} else if (clientSystemInfo != null && clientSystemInfo.toUpperCase().indexOf(C_VERSION_KIND_IOS) >= 0) {// ios版本
				sysMrk = C_VERSION_KIND_IOS;
			} else {// 如果为空，默认为 andorid
				sysMrk = C_VERSION_KIND_ANDROID;
			}

			String sql = "select * from t_s_version where   rownum =1 and   "
					+ "operate_tm = (select max(operate_tm) from t_s_version i where i.sys_mrk='" + sysMrk + "'"
					// + " and i.sys_cde=#{sysCde}
					+ ") and sys_mrk='" + sysMrk + "' ";
			// + "and sys_cde=#{sysCde}";

			List<Map<String, Object>> versionList = appService.findForJdbc(sql, 1, 1);
			

			if (versionList != null && versionList.size() > 0) {
				for (int i = 0; i < versionList.size(); i++) {
					// {"downUrl":"http://122.224.64.136:7001/mobile/apk/","iosName":"ZSSingle.ipa","AndroidName":"ZSSingle.apk"}

					TSSystemEntity sysSystem = appService.findUniqueByProperty(TSSystemEntity.class, "sysKey",
							"verPath");
					if (null != sysSystem && null != sysSystem.getSysValse()) {
						Map<String, String> map = (Map<String, String>) com.alibaba.fastjson.JSONObject
								.parse(sysSystem.getSysValse());

						if (null != map) {
							urlStr = map.get("downUrl");
							if (sysMrk.equals(C_VERSION_KIND_ANDROID)) {// andorid版本较验
								urlStr += map.get("AndroidName");
								verDownloadUrl = map.get("downUrl") + versionList.get(i).get("fileName") + "";
							} else if (sysMrk.equals(C_VERSION_KIND_IOS)) {// ios版本
								urlStr += map.get("iosName");
								verDownloadUrl = map.get("iosUrl");
							}
						}
					}

					version.setLatestVersion(versionList.get(i).get("ver") + "");// 版本号
					version.setUpdateDate(versionList.get(i).get("operate_tm") + "");// 更新时间
					version.setUpdateDetails(versionList.get(i).get("operate_tm") + "");// 更新备注
					version.setDownloadUrl(urlStr);// 版本下载路径(原始包)
					version.setVerDownloadUrl(verDownloadUrl);// 升级包下载地址
																// (增量包)
					List<VOBase> verList = new ArrayList<VOBase>();
					verList.add(version);
					returnVo.setList(verList);
					returnVo.setResultCde("1");
					returnVo.setMessage("获取版本信息成功");
					returnVo.setAction("task");
					returnVo.setMethod("getVersion");
					
					break;
				}

			} else {
				returnVo.setResultCde("1");
				returnVo.setMessage("获取版本信息成功");
				returnVo.setAction("task");
				returnVo.setMethod("getVersion");
			}
		} catch (Exception e) {
			returnVo.setResultCde("1");
			returnVo.setMessage("获取版本信息成功");
			returnVo.setAction("task");
			returnVo.setMethod("getVersion");
			logger.error("系统异常：",e);
		}

		return returnVo;
	}
}
